package com.loan.controller;
import java.util.Date;
import java.util.Map;

import com.jfinal.core.Controller;
import com.loan.model.Data;
import com.loan.model.InvestLog;
import com.loan.model.User;
import com.loan.service.InvestLogService;
import com.loan.util.Json;
 
public class InvestLogController extends Controller {
	private static InvestLogService investLog = new InvestLogService();
	
	/**
	 *  获取列表列表
	 */
	public void list() {
		renderJson(Json.ok("数据获取成功！", investLog.list(Data.flat(getParaMap()))));
	}	
	
	/**
	 *  获取我的明细列表
	 */
	public void myList() {
		User u = getAttr("user");
		int page = getParaToInt("page",1);
		int size = getParaToInt("size",10);
		Map<String, String> params = Data.flat(getParaMap());
		params.put("userId", String.valueOf(u.getId()));
		renderJson(Json.ok("数据获取成功！", investLog.list(page, size, params)));
	}
	
	/**
	 * 编辑公司信息
	 */
	public void edit() {
		int id = getParaToInt("id",0);
		InvestLog item = id>0 ? InvestLog.dao.findById(id) : new InvestLog();
		item.setName(getPara("name"));
		if(id>0 ? item.update() : item.setCreateTime(new Date()).save()){
			renderJson(Json.ok("公司信息编辑成功！")); 
		}else{
			renderJson(Json.error("公司信息编辑失败！"));
		}
	}
	
	/**
	 *  获取公司信息
	 */
	public void info() {
		renderJson(Json.ok("数据获取成功！", InvestLog.dao.findById(getParaToInt("id",0))));
	}
}
 